package jzoffer;

import java.util.Deque;
import java.util.LinkedList;
import java.util.TreeSet;

/**
 * @author MaoLin Wang
 * @description 使用两个栈实现队列的pop和push
 * @date 2020-08-24 08:32
 */
class CQueue {
    private Deque<Integer> inQueue;
    private Deque<Integer> outQueue;
    int size;
    public CQueue() {
        inQueue=new LinkedList();
        outQueue=new LinkedList();
    }
    
    public void appendTail(int value) {
        inQueue.push(value);
        size++;
    }
    
    public int deleteHead() {
        if (size==0){
            return -1;
        }
        if (outQueue.isEmpty()){
            while (!inQueue.isEmpty()){
                outQueue.push(inQueue.pop());
            }
        }
        if (!outQueue.isEmpty()){
            size--;
            return outQueue.pop();
        }else {
            return -1;
        }
    }

    public static void main(String[] args) {
        TreeSet treeMap=new TreeSet();
        treeMap.add(1);
        treeMap.add(2);
        System.out.println(treeMap);
    }
}

/**
 * Your CQueue object will be instantiated and called as such:
 * CQueue obj = new CQueue();
 * obj.appendTail(value);
 * int param_2 = obj.deleteHead();
 */